package com.hualude.roadsign.repository;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.PortBlueRuleDto;
import com.hualude.roadsign.dto.PortRedRuleDto;
import com.hualude.roadsign.model.PortBlueRuleEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

/**
 * Created by xu_jiaHui on 2017/12/9.
 */
public interface PortBlueRuleRepository extends CrudRepository<PortBlueRuleEntity, Integer> {

    /**
     * @Description: 获取常规规则用于DT展示
     * @author xu_jiaHui
     * @date 2017/12/9 16:28
     */
    public List<PortBlueRuleDto> getPortBlueRule4DT(DTRequestDto dtRequestDto, Integer alarmId);

    /**
     * @Description:
     * @author xu_jiaHui
     * @date 2017/12/9 16:29
     */
    @Query(value = "select count(*) from PortBlueRuleEntity where alarmId=?1")
    public Integer getPortBlueRuleCount4DT(Integer alarmId);

    /**
     * @Description:
     * @author weiyuxian
     * @date 2018/4/24 17:50
     */
    @Modifying
    @Query(value = "delete from PortBlueRuleEntity where ruleModelId=?1")
    public Integer deletePortBlueRuleByRuleModelId(Integer ruleModelId) throws Exception;

    public List<PortRedRuleDto> getBlueRuleByModelId(DTRequestDto dtRequestDto, Integer modelId)throws Exception;

    public Integer getBlueRuleCountByModelId(DTRequestDto dtRequestDto, Integer modelId)throws Exception;

    @Modifying
    @Query(value = "update PortBlueRuleEntity set blueRuleLevel=?2,blueRuleName=?3,blueRuleContent=?4,blueRuleFlag=?5 where blueRuleId=?1")
    Integer updateRule(Integer blueRuleId, Integer blueRuleLevel, String blueRuleName, String blueRuleContent, String blueRuleFlag);
}
